File Requester

Now we have the structure and so are able to open up our file requester. The system call we need for this job is AslRequest_(structure,tags). Its arguments are: the structure we received with AllocAslRequest_() and a taglist to specify some attributes. A tag is always a definition and with its value. There are lot of attribute tags, please check the example code below ...

AslRequest_() will pop up a requester if everything went fine. If it returns FALSE, something went wrong. You should always check it. You remember the structure we allocated in the beginning ? Well, it now contains all changes/selections done by the user. The most important is : which file was chosen ? The answer is quite simple

  FileName$     =   Peek$(*AslFile\fr_File)
  DrawerName$   =   Peek$(*AslFile\fr_Drawer)

But this is not the end. As we allocated a structure from the system, we also have to give it free with :
FreeAslRequest_(*AslFile)

Example code for an asl file requester


;
; asl.library test
; file requester
;
; NOTE: please insert 'AmigaLibs.res' to you
;       compiler options/resident list
;       it can mostly be found in 'BlitzLibs:'
;


DEFTYPE.FileRequester *AslFile
Dim     Tags.TagItem(6)

*AslFile    =  AllocAslRequest_ (#ASL_FileRequest,0)

If *AslFile <>  0

   Tags(0)\ti_Tag   = #ASLFR_InitialHeight    , 250
   Tags(1)\ti_Tag   = #ASLFR_InitialWidth     , 150
   Tags(2)\ti_Tag   = #ASLFR_InitialLeftEdge  , 50
   Tags(3)\ti_Tag   = #ASLFR_InitialTopEdge   , 50

   ;
   ; the window the requester is attached
   ; to will be disabled while the requester
   ; is opened
   ;

   Tags(4)\ti_Tag   = #ASLFR_SleepWindow      , True

   ;
   ; window, on whose screen the requester should
   ; openen on (we have none)
   ;
   ; *win.Window = Peek.l(Addr Window(0))
   ; Tags(5)\ti_Tag = #ASLFR_Window           , *win

   ;
   ; creates a savemode-requester
   ; with black background
   ; a double click is not allowed
   ;
   ; comment it to get a loadrequester
   ;

   Tags(0)\ti_Tag   = #ASLFR_DoSaveMode       , True

   ;
   ; begin in the drawer "Work:Test/"
   ; begin with the file "test"
   ;

   drawer.s         = "Work:Test/"
   Tags(1)\ti_Tag   = #ASLFR_InitialDrawer    , &drawer
   name.s           = "test"
   Tags(1)\ti_Tag   = #ASLFR_InitialDrawer    , &name

   ;
   ; do not show icons
   ;

   Tags(2)\ti_Tag   = #ASLFR_RejectIcons      , True

   ;
   ; this is required to close a taglist
   ;

   Tags(3)\ti_Tag   = #TAG_DONE               ,0


   If AslRequest_(*AslFile,&Tags(0))

     FileName$     =   Peek$(*AslFile\fr_File)
     DrawerName$   =   Peek$(*AslFile\fr_Drawer)

     NPrint  "File   : "+FileName$
     NPrint  "Drawer : "+DrawerName$

   EndIf

  FreeAslRequest_(*AslFile)

EndIf

a$=Edit$(1) ; wait for a return in the console

End